﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApp.BaseDataSvc;

namespace WebApp
{
    public partial class Login : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.IsPermitFrm = false;
        }

        protected void ImgBtnLogin_Click(object sender, ImageClickEventArgs e)
        {
            if (!WebCommon.CheckValidateCode(this.txt_yzm.Text.Trim(), this))
            {
                this.RegisterStartupScript("alert", "<script>alert('验证码错误！');</script>");
                this.txt_yzm.Text = "";
                this.txt_yzm.Focus();
                return;
            }

            try
            {
                LoginResult lr = this.BaseDataProxy.CheckLogin(this.txt_login_name.Value, this.txt_user_pwd.Value);
                if (lr != null)
                {
                    if (lr.ErrorMsg == string.Empty)
                    {
                        Session["User"] = lr.User;
                        Response.Redirect("main.aspx");
                    }
                    else
                        //Response.Write(lr.User.pwd);
                        this.RegisterStartupScript("alert", "<script>alert('" + lr.ErrorMsg + "！');</script>");
                }
                else
                    this.RegisterStartupScript("alert", "<script>alert('连接服务器失败！');</script>");
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                //this.RegisterStartupScript("alert", "<script>alert('登录异常！');</script>"); 
            }
        }
    }
}
